from scipy import average
from core.agent import Agent

class TitForTat(Agent):
    """Invest if half or more of neighbors invested in the last round."""
    
    def decide(self, my_id, info):
        # In the first round, invest
        if info.current_round == 1:
            return True
        # Subsequently, invest if >= 50% of neighbors invested in the last round
        d = info.all_decisions()
        p = average([d[i] for i in info.neighbors()])
        return p >= .5